<!DOCTYPE html>
<html>
<head>
    <title>发布活动</title>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">

    <meta name="description" content="">

    <link rel="stylesheet" href="dist/lib/weui.css">
    <link rel="stylesheet" href="dist/css/build.css">
    <link rel="stylesheet" href="dist/css/jquery-weui.css">
    <link href="dist/lib/imgUp.css?v2" rel="stylesheet"/>

    <style>
        body {
            background: #f5f5f5
        }

        .weui-cells.weui-cells_form {
            background: #fff;
            /*-moz-box-shadow: 2px 2px 5px #333333;*/
            /*-webkit-box-shadow: 0px 2px 15px #eee;*/
            /*box-shadow: 0px 2px 15px #eee;*/
            /*border-bottom: 1px solid #EDEDED;*/
        }

        .weui-uploader__input-box {
            margin-top: 5px;
        }

    </style>
</head>

<body>


<div class="weui-cells weui-cells_form">
    <div class="weui-cell">
        <div class="weui-cell__hd"><label class="weui-label">活动标题</label></div>
        <div class="weui-cell__bd">
            <input class="weui-input" id="title" type="" placeholder="请输入活动标题">
        </div>
    </div>


    <div class="weui-cell">
        <div class="weui-cell__hd"><label for="beginDate" class="weui-label">开始日期</label></div>
        <div class="weui-cell__bd">
            <input class="weui-input" id="beginDate" placeholder="请选择" type="text">
        </div>
    </div>


    <div class="weui-cell weui-cell_access">
        <div class="weui-cell__hd"><label for="endDate" class="weui-label">结束日期</label></div>
        <div class="weui-cell__bd">
            <input class="weui-input" id="endDate" placeholder="请选择" type="text">
        </div>
    </div>


    <div class="weui-cell">
        <div class="weui-cell__hd"><label class="weui-label">活动地址</label></div>
        <div class="weui-cell__bd">
            <input class="weui-input" id="locale" type="" placeholder="请输入活动地址">
        </div>
    </div>


</div>
<div class="weui-cells__title">详细说明</div>
<div class="weui-cells weui-cells_form">
    <div class="weui-cell">
        <div class="weui-cell__bd">
            <textarea class="weui-textarea" id="comment" placeholder="请输入活动说明" rows="5"></textarea>
        </div>
    </div>
</div>

<div class="weui-cells__title">活动图片</div>
<div class="weui-cells weui-cells_form">

    <div class="weui-cell">
        <div class="weui-cell__bd">
            <div class="weui-uploader">
                <div class="weui-uploader__bd">
                    <ul class="z_photo upimg-div clear">
                        <li class="z_file fl" id="z_file">
                            <div class="add-img weui-uploader__input-box"></div>
                            <input type="file" name="file" id="file" class="file" value="" placeholder="1"
                                   accept="image/*" multiple/>
                        </li>
                    </ul>
                </div>
            </div>
        </div>
    </div>
</div>

<div class="weui-btn-area">
    <a class="weui-btn weui-btn_primary" href="javascript:" id="postActivity">确定</a>
</div>

<script src="dist/lib/jquery-2.1.4.js"></script>
<script src="dist/lib/fastclick.js"></script>
<script>
    $(function () {

        FastClick.attach(document.body);

        $("#beginDate").calendar({
            // container:'请选择'

            onChange: function (p, values, displayValues) {
                console.log(values, displayValues);
            }
        });
        $("#endDate").calendar({
            onChange: function (p, values, displayValues) {
                console.log(values, displayValues);
            }
        });

    });
</script>
<script src="dist/js/jquery-weui.js"></script>
<script src="dist/lib/vue.min.js"></script>
<script src="dist/lib/http.js"></script>
<script src="dist/lib/imgUp.js"></script>
<script src="dist/lib/jquery.cookie.js"></script>

<script>

    $http.getUserSignIn(true, 'activity_add.html');
    console.log($http.getUserSignIn());

    $(document).on("click", "#postActivity", function () {

        var title = $('#title').val();
        var beginDate = $('#beginDate').val();
        var endDate = $('#endDate').val();
        var locale = $('#locale').val();
        var comment = $('#comment').val();
        var img = getValues('imgFile');


        var rs = {
            title: title,
            locale: locale,
            beginDate: beginDate,
            endDate: endDate,
            comment: comment,
            photoFrontConverUrl: img,
            personnels: 1,
            wechatId: $http.getUserSignIn().phone
        };

        $http.post($http.postActivityAdd(rs)).then(function (data) {
            if (data.success == true) {
                $.alert(data.message, '提示', function () {

                    $.cookie('activity', $http.getCookieArray(data.data.id, data.data.title));

                    // window.location.href = 'activity_details.html';
                    window.location.href = 'activity_details.html?id=' + data.data.id + '&title=' + data.data.title;
                })

            } else {
                $.alert(data.message, '提示')
            }
        }, function (err) {
            console.log(err);
            return err;
        });

    });

    function getValues(inputName) {
        var values = [];
        $('input[name=' + inputName + ']').each(function (i, v) {
            values.push(v.value);
        })
        return values.join(',');
    }

</script>
</body>
</html>
